using System;
using System.Windows.Forms;

namespace Insesoft.UI
{
    public partial class ErrorForm : Form
    {
        private readonly Exception exception;
        private readonly string titulo = "";

        #region Constructors

        private ErrorForm(string titulo)
        {
            InitializeComponent();
            this.titulo = titulo;
        }

        public ErrorForm(string titulo, Exception exception)
            : this(titulo)
        {
            this.exception = exception;
        }

        #endregion
        

        private void ErrorFormLoad(object sender, EventArgs e)
        {
            lblTitulo.Text = titulo;
            txtDetalle.Text = (exception != null) ? exception.Message : "No se detalla el errror";
            MostrarOcultarDetalles();
        }

        private void BtnDetalleClick(object sender, EventArgs e)
        {
            MostrarOcultarDetalles();
        }             

        private void BtnSalirClick(object sender, EventArgs e)
        {
            Close();
        }

        private void MostrarOcultarDetalles()
        {
            if (plDetalles.Top + plDetalles.Height > Height)
            {
                Height = plDetalles.Top + plDetalles.Height + 30;
                btnDetalle.Text = "<< Detalles";
            }
            else
            {
                Height = plDetalles.Top + 10;
                btnDetalle.Text = "Detalles >>";
            }
        }
    }
}